import { Navigate } from 'react-router'
import { useUserStore } from '@/stores/userStore.js'

const PrivateRoute = ({ children }) => {
	const token = useUserStore((state) => state.token)

	console.log('token: ', token)
	const logged = token ? true : false

	// useEffect(() => {
	// 	console.log('currentUser: ', currentUser)
	// 	setUser({ ...user, username: currentUser?.username || '', logged: true })
	// }, [currentUser])

	if (!token) {
		return <Navigate to="/login" />
	}

	return logged ? <>{children}</> : <Navigate to="/login" />
}

export default PrivateRoute
